package main.java.design.singleton;

/**
 * <p>
 *  双重检查模式
 * </p>
 *
 * @author : wangdejian
 * @version 1.0
 * @date : 2020/6/8 19:55
 */
public class Singleton_3 {

    // 私有构造方法
    private  Singleton_3() {}

    // 此处使用valotile起到禁止指令重排的作用，可以保证双端检锁机制线程安全
    private volatile static Singleton_3 INSTANCE;

    public static Singleton_3 getInstance() {
        if (null == INSTANCE) {
            synchronized (Singleton_3.class) {
                if (null == INSTANCE) {
                    INSTANCE = new Singleton_3();
                }
            }
        }
        return INSTANCE;
    }
}
